﻿// Note: This source code is derived from the Analog Clock tutorial
// at http://blogs.windowsclient.net/orlando_perri/archive/2009/07/29/implementing-an-analogic-clock-in-wpf.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Timers;
using System.Diagnostics;

namespace WPF_GUI
{    
    public class Clock : INotifyPropertyChanged
    {
        private Timer timer = new Timer(1000);

        public Clock()
        {
            timer.Elapsed += new ElapsedEventHandler((sender, e) => OnPropertyChanged(null));
            timer.Start();
        }

        public int Seconds
        {
            get
            {
                return DateTime.Now.Second;
            }
        }

        public int Minutes
        {
            get
            {
                return DateTime.Now.Minute;
            }
        }

        public int Hours
        {
            get
            {
                return DateTime.Now.Hour;
            }
        }

        public string CurrentTime
        {
            get
            {
                string hoursString = "";
                string minutesString = "";
                string secondsString = "";

                if (Hours < 10)
                {
                    hoursString = "0";
                }
                hoursString += Hours;

                if (Minutes < 10)
                {
                    minutesString = "0";
                }
                minutesString += Minutes;

                if (Seconds < 10)
                {
                    secondsString = "0";
                }
                secondsString += Seconds;

                return hoursString + ":" + minutesString + ":" + secondsString;
            }
        }

        #region INotifyPropertyChanged Members

        private void OnPropertyChanged(string property)
        {
            if (PropertyChanged != null)
                PropertyChanged(this, new PropertyChangedEventArgs(property));
        }

        public event PropertyChangedEventHandler PropertyChanged;

        #endregion
    }     
}
